package com.chaotic_era;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.ArrayList;
import java.util.List;

public class CodeGenerator {
    public static void main(String[] args) {
        // 代码生成器
        AutoGenerator mpg = new AutoGenerator();
        // 全局配置
        GlobalConfig gc = new GlobalConfig();
        String projectPath = System.getProperty("user.dir");
        gc.setOutputDir(projectPath + "/src/main/java");
        gc.setAuthor("chaotic_era");
        gc.setOpen(false);
//        gc.setSwagger2(true);
        gc.setIdType(IdType.AUTO);
        gc.setBaseResultMap(true);
        mpg.setGlobalConfig(gc);

        //达梦数据库的配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setDbType(DbType.DM);
        dsc.setSchemaName("LOGISINFO");
        dsc.setUrl("jdbc:dm://127.0.0.1:5236?schema=LOGISINFO");
        dsc.setDriverName("dm.jdbc.driver.DmDriver");
        dsc.setUsername("SYSDBA");
        dsc.setPassword("SYSDBA");
        mpg.setDataSource(dsc);

        // 包配置
        PackageConfig pc = new PackageConfig();
//        pc.setModuleName(scanner("模块名"));
        pc.setParent("com.chaotic_era");
        pc.setEntity("pojo");
        pc.setMapper("mapper");
        mpg.setPackageInfo(pc);

        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        strategy.setNaming(NamingStrategy.underline_to_camel);
        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
        strategy.setEntityLombokModel(true);
//        strategy.setInclude(scanner("表名"));
        strategy.setSuperEntityColumns("id");//还没设置主键
        strategy.setControllerMappingHyphenStyle(true);
//        strategy.setTablePrefix(pc.getModuleName() + "_");
        strategy.setEntityLombokModel(true);
        mpg.setStrategy(strategy);
        mpg.execute();
    }
}

